<?php 
class App_model_site extends Model {
    private $table_site = 'site';
    private $table_router = 'router';
    private $table_cdn = 'cdn';
    private $table_css = 'css';
    private $table_js = 'js';
    
    
    public function get_info($server_name = '') {
        $sql = "SELECT `s`.`id` `site_id`,`s`.`caption` `caption`,`s`.`name` `name`,`s`.`base_path` `base_path`," . 
            "`s`.`router_id` `router_id`, `s`.`level` `level`," . 
            "`r`.`module` `module`,`r`.`action` `action`,`r`.`access_mode` `access_mode` " .
            "FROM `{$this->table_site}` `s` INNER JOIN `{$this->table_router}` `r` ON `s`.`router_id`=`r`.`id` " .
            "WHERE `s`.`server_name`='{$server_name}'";
        
        return $this->db->row($sql);
    }
    
    
    public function get_csses($theme) {
        /*$sql = "SELECT `css` FROM `{$this->table_css}` WHERE `theme`='$theme'";
        return $this->db->rows($sql);*/
        return $this->db->select_rows(
            $this->table_css,
            array('css'),
            array('theme' => $theme)
        );
    }
    
    
    public function get_jses($theme) {
        /*$sql = "SELECT `js` FROM `{$this->table_js}` WHERE `theme`='$theme'";
        return $this->db->rows($sql);*/
        return $this->db->select_rows(
            $this->table_js,
            array('js'),
            array('theme' => $theme)
        );
    }
    
    
    public function get_cdn_info($cdn_id) {
        $cdn_id = (int) $cdn_id;
        /*$sql = "SELECT `base_url`, `base_dir` FROM `{$this->table_cdn}` WHERE `id`='{$cdn_id}' LIMIT 1";
        return $this->db->row($sql);*/
        return $this->db->select_rows(
            $this->table_cdn,
            array('base_url', 'base_dir'),
            array('id' => $cdn_id)
        );
    }
}
?>